package com.qing.demo.netty.web;

import com.qing.demo.netty.domain.User;
import com.qing.demo.netty.server.NettyServer;
import com.qing.demo.netty.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author caozhipeng
 * @date 2025/7/29
 */
@Controller
@RestController
@RequestMapping("/netty")
public class NettyController {

    @Resource
    private NettyServer nettyServer;

    @Autowired
    private UserService userService;

    @RequestMapping("/localAddress")
    public String localAddress() {
        return "nettyServer localAddress " + nettyServer.getChannel().localAddress();
    }

    @GetMapping("/queryAll")
    public Page<User> queryAll(@RequestParam (required = false, defaultValue = "",value = "name") String name,
                               @RequestParam (required = false, defaultValue = "0",value = "pageNumber") int pageNumber,
                               @RequestParam (required = false, defaultValue = "10",value = "pageSize") int pageSize) {
        return userService.findByName(name, pageNumber, pageSize);
    }



}
